package com.sdp.irrigation.db.irrigation_field.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.core.bizc.db.IViewQuery;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.irrigation.db.irrigation_field.mapper.IrrigationFieldMapper;
import com.sdp.irrigation.db.irrigation_field.service.IIrrigationFieldService;
import com.sdp.irrigation.entity.IrrigationField;

/**
 * <p>
 * 田块台账信息 服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-12-14
 */
@Service
public class IrrigationFieldServiceImpl extends ServiceImpl<IrrigationFieldMapper, IrrigationField> implements IIrrigationFieldService ,IViewQuery{

	@Autowired
	private IrrigationFieldMapper irrigationFieldMapper;
	
	@Override
	public List<IrrigationField> queryAllField() {
		LambdaQueryWrapper<IrrigationField> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.orderByDesc(IrrigationField::getCreateTime);
		return list(lambdaQueryWrapper); 
	}

	@Override
	public <T> List<T> viewList(QueryWrapper<T> queryWrapper,DataCenter dc) {
		return irrigationFieldMapper.viewList(queryWrapper,dc);
	}

	@Override
	public <T> int viewCount(QueryWrapper<T> queryWrapper) {
		return irrigationFieldMapper.viewCount(queryWrapper);
	}

	@Override
	public <T> IPage<T> viewPage(IPage<T> page, QueryWrapper<T> queryWrapper,DataCenter dc) {
		return irrigationFieldMapper.viewPage(page, queryWrapper,dc);
	}

	@Override
	public List<IrrigationField> queryFieldByProjectNo(String projectNo) {
		LambdaQueryWrapper<IrrigationField> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(IrrigationField::getProjectNo, projectNo);
		return list(lambdaQueryWrapper);
	}

	@Override
	public IrrigationField queryFieldByFieldNo(String fieldNo) {
		LambdaQueryWrapper<IrrigationField> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(IrrigationField::getFieldNo, fieldNo);
		return getOne(lambdaQueryWrapper,false);
	}

	@Override
	public void updateTime() {
	
		LambdaUpdateWrapper<IrrigationField> createTimeUpdateWrapper = new LambdaUpdateWrapper<>();
		createTimeUpdateWrapper.set(IrrigationField::getCreateTime, LocalDateTime.now());
		createTimeUpdateWrapper.isNull(IrrigationField::getCreateTime);
		update(createTimeUpdateWrapper);
		
		LambdaUpdateWrapper<IrrigationField> updateTimeUpdateWrapper = new LambdaUpdateWrapper<>();
		updateTimeUpdateWrapper.set(IrrigationField::getUpdateTime, LocalDateTime.now());
		updateTimeUpdateWrapper.isNull(IrrigationField::getUpdateTime);
		update(updateTimeUpdateWrapper);
	}

}
